package aps

import glory.xxd.Utils

/**
 * 更换物料
 */
class ChangeMeterialController {

    def commentService

    def index() {

        def MaterialPartNo = params.MaterialPartNo ?: ""
        def EqpId = params.EqpId ?: ""
        def ChangeMeterialType = params.ChangeMeterialType?:''
        def OPID = params.OPID ?: ""
        def Type = params.Type ?: ""
        def RemainTime = params.RemainTime ?: ""
        def Size = params.Size ?: ""
        def Device = params.Device ?: ""
        def WaferSource = params.WaferSource ?: ""
        def Diagram = params.Diagram ?: ""
        def ThawEndTime = params.ThawEndTime ?: ""
        def SawLength = params.SawLength ?: ""
        def SawThickness = params.SawThickness ?: ""
        def ExternalDiameter = params.ExternalDiameter ?: ""
        def InternalDiameter = params.InternalDiameter ?: ""
        def StartTime = params.StartTime ?: ''
        def MaterialLotNo = params.MaterialLotNo ?: ''
        def EndTime = params.EndTime ?: ''
        def BBD = params.BBD ?: ''
        def NCS = params.NCS ?: ''
        def MesMaterial = [MaterialPartNo  : MaterialPartNo,
                           Size            : Size,
                           RemainTime      : RemainTime,
                           Type            : Type,
                           Name            : params.Name ?: '',
                           SeqNo           : params.SeqNo ?: '',
                           Device          : Device,
                           WaferSource     : WaferSource,
                           Diagram         : Diagram,
                           ThawEndTime     : ThawEndTime,
                           EndTime         : EndTime,
                           SawLength       : SawLength,
                           SawThickness    : SawThickness,
                           ExternalDiameter: ExternalDiameter,
                           InternalDiameter: InternalDiameter,
                           StartTime       : StartTime,
                           MaterialLotNo   : MaterialLotNo,
                           BBD             : BBD,
                           NCS             : NCS]
        MesMaterial = Utils.getXmlByJSONHtml(MesMaterial)

        def Materials = [MesMaterial: "${MesMaterial}"]
        Materials = Utils.getXmlByJSONHtml(Materials)

        def InputDataList = Utils.getXmlByJSONHtml(params.InputDataList)
        print InputDataList
        def body = [EqpId: EqpId, OPID: OPID,ChangeMeterialType:ChangeMeterialType, Materials: "${Materials}", INPUTDATALIST: InputDataList]
        body = Utils.getXmlByJSONHtml([Body: Utils.getXmlByJSONHtml(body)])
        String logUUID = Utils.getUUID();

        def header = [MESSAGENAME: "ChangeMeterial", TRANSACTIONID: logUUID, USERNAME: "EAP"]
        header = Utils.getXmlByJSONHtml(header)
        header = [Header: header]
        header = Utils.getXmlByJSONHtml(header)
        def requestStr = header + body
        def xml = [Request: requestStr]

        xml = Utils.getXmlByJSONHtml(xml)

        def json = commentService.getJsonByObjectForTopic2Queue(logUUID, xml)

        render json
    }


    def testJson() {
        def xml = """
            <MATERIALINFO>
                <ID />
                <MaterialPartNo>240004</MaterialPartNo>
                <Type>Epoxy</Type>
                <SeqNo />
                <Size />
                <ThawEndTime>11-16?16:01</ThawEndTime>
                <SawLength />
                <SawThickness />
                <InternalDiameter></InternalDiameter>
                <ExternalDiameter />
                <EqpID>1FD1100</EqpID>
                <Qty>0</Qty>
            </MATERIALINFO>
"""

        def data = Utils.getJsonObjectByXML_1(xml)

        def str = Utils.getFormatString(data)

        render str
    }
}
